package com.ruoyi.web.controller.production.seed;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.production.domain.seed.SeedApplyTemporary;
import com.ruoyi.production.service.seed.ISeedApplyTemporaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 种子临时申请Controller
 *
 * @author ruoyi
 * @date 2021-07-08
 */
@RestController
@RequestMapping("/seed/applyTemporary")
@Api(value = "种子临时量",tags = "种子临时相关API")
public class SeedApplyTemporaryController extends BaseController
{
    @Autowired
    private ISeedApplyTemporaryService seedApplyTemporaryService;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询种子临时申请列表
     */
    @PreAuthorize("@ss.hasPermi('seed:temporary:list')")
    @GetMapping("/list")
    @ApiOperation("获取种子临时申请表信息")
    @ApiImplicitParam(name = "seedApplyTemporary",value = "种子临时申请实体类",paramType = "body", dataType = "SeedApplyTemporary")
    public TableDataInfo list(SeedApplyTemporary seedApplyTemporary)
    {
        startPage();
        List<SeedApplyTemporary> list = seedApplyTemporaryService.selectSeedApplyTemporaryList(seedApplyTemporary);
        return getDataTable(list);
    }

    /**
     * 导出种子临时申请列表
     */
    @PreAuthorize("@ss.hasPermi('seed:temporary:export')")
    @Log(title = "种子临时申请", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出种子临时申请表信息")
    @ApiImplicitParam(name = "seedApplyTemporary",value = "种子临时申请实体类",paramType = "body", dataType = "SeedApplyTemporary")
    public AjaxResult export(SeedApplyTemporary seedApplyTemporary)
    {
        List<SeedApplyTemporary> list = seedApplyTemporaryService.selectSeedApplyTemporaryList(seedApplyTemporary);
        ExcelUtil<SeedApplyTemporary> util = new ExcelUtil<SeedApplyTemporary>(SeedApplyTemporary.class);
        return util.exportExcel(list, "种子临时申请数据");
    }

    /**
     * 获取种子临时申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('seed:temporary:query')")
    @GetMapping(value = "/{seedApplyTemporaryId}")
    @ApiOperation("获取种子临时申请表单个信息")
    @ApiImplicitParam(name = "seedApplyTemporaryId",value = "种子临时申请实体类主键",paramType = "path", dataType = "Long")
    public AjaxResult getInfo(@PathVariable("seedApplyTemporaryId") Long seedApplyTemporaryId)
    {
        return AjaxResult.success(seedApplyTemporaryService.selectSeedApplyTemporaryById(seedApplyTemporaryId));
    }

    /**
     * 新增种子临时申请
     */
    @PreAuthorize("@ss.hasPermi('seed:temporary:add')")
    @Log(title = "种子临时申请", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增种子临时申请表信息")
    @ApiImplicitParam(name = "seedApplyTemporary",value = "种子临时申请实体类",paramType = "body", dataType = "SeedApplyTemporary")
    public AjaxResult add(@RequestBody SeedApplyTemporary seedApplyTemporary)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        seedApplyTemporary.setUserId(loginUser.getUser().getUserId());
        return toAjax(seedApplyTemporaryService.insertSeedApplyTemporary(seedApplyTemporary));
    }

    /**
     * 修改种子临时申请
     */
    @PreAuthorize("@ss.hasAnyPermi('seed:temporary:edit,seed:temporary:permit1,seed:temporary:permit2')")
    @Log(title = "种子临时申请", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    @ApiOperation("修改种子临时申请表信息")
    @ApiImplicitParam(name = "seedApplyTemporary",value = "种子临时申请实体类",paramType = "body", dataType = "SeedApplyTemporary")
    public AjaxResult edit(@RequestBody SeedApplyTemporary seedApplyTemporary)
    {
        return toAjax(seedApplyTemporaryService.updateSeedApplyTemporary(seedApplyTemporary));
    }

    /**
     * 删除种子临时申请
     */
    @PreAuthorize("@ss.hasPermi('seed:temporary:remove')")
    @Log(title = "种子临时申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{seedApplyTemporaryIds}")
    @ApiOperation("删除种子临时申请表信息")
    @ApiImplicitParam(name = "seedApplyTemporaryIds",value = "种子临时申请实体类主键数组",paramType = "path", dataType = "Long")
    public AjaxResult remove(@PathVariable Long[] seedApplyTemporaryIds)
    {
        return toAjax(seedApplyTemporaryService.deleteSeedApplyTemporaryByIds(seedApplyTemporaryIds));
    }
}
